package com.csdj.music.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csdj.music.vo.Comment;
import com.csdj.music.service.CommentService;
import com.csdj.music.mapper.CommentMapper;
import com.csdj.music.vo.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
* @author XuTao
* @description 针对表【comment】的数据库操作Service实现
* @createDate 2023-03-13 15:46:15
*/
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService{
    @Autowired(required = false)
    private CommentMapper commentMapper;
    @Override
    public RespBean insert(Comment comment) {
        if (commentMapper.insert(comment)>0){
            return RespBean.success("200","添加成功");
        }
        return RespBean.error("500","添加失败");
    }

    @Override
    public RespBean update(Comment comment) {
        SimpleDateFormat format=new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
        Date data=new Date();
        String date=format.format(data);
        Date time= null;
        try {
            time = format.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        comment.setCreate_time(time);
        if (commentMapper.update(comment)>0){
            return RespBean.success("修改成功");
        }
        return RespBean.error("修改失败");
    }

    @Override
    public RespBean delete(Integer id) {
        if(commentMapper.delete(id)>0){
            return RespBean.success("200","删除成功");
        }
        return RespBean.success("500","删除失败");
    }

    @Override
    public List<Comment> selectByPrimarykey(Integer id) {
        return commentMapper.selectByPrimarykey(id);
    }

    @Override
    public List<Comment> allComment() {
        return commentMapper.allComment();
    }

    @Override
    public List<Comment> commentOfSongId(Integer songId) {
        return commentMapper.commentOfSongId(songId);
    }

    @Override
    public List<Comment> commentOfSongListId(Integer songListId) {
        return commentMapper.commentOfSongListId(songListId);
    }
}




